
#!/bin/bash

###
# @Author: Logan.Li
# @Gitee: https://gitee.com/attacker
# @email: admin@attacker.club
# @Date: 2025-09-06 23:04:00
# @LastEditTime: 2025-09-07 10:55:16
# @Description: Demo SpringBoot Nacos项目简单启动脚本
###

JAR_FILE="demo.jar"
LOG_DIR="logs"

echo "==================== 启动demo-springboot【开始】 ===================="

# 创建日志目录
if [ ! -d "$LOG_DIR" ]; then
    mkdir -p "$LOG_DIR"
    echo "创建日志目录: $LOG_DIR"
fi

# 杀死已有进程
pid=`ps -aux | grep $JAR_FILE | grep -v grep | awk '{print $2}'`
if test -z "$pid"
then
    echo "原有进程没有启动"
else
    echo "杀死原有进程【$pid】"
    kill -9 $pid
fi

# 启动应用
nohup java -Dnacos.config.namespace=test \
        -Dnacos.config.server-addr=127.0.0.1:8848 \
        -Dnacos.config.username=nacos \
        -Dnacos.config.password=d1xxxxxx \
        -jar $JAR_FILE >/dev/null 2>&1 &

# 获取新进程PID
pid=`ps -aux | grep $JAR_FILE | grep -v grep | awk '{print $2}'`
echo "springboot 服务已启动，PID:【 $pid 】"


      